package com.harveyh.cemax.bean;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.graphics.Bitmap;

public class ShiTiBean extends BaseBean {
	public int localId;
	public int id;
	/** 级别*/
	public String jibie = "";
	/** 题目类型：xuanze，panduan*/
	public String timuType = "";
	/** 题目描述*/
	public String timu = "";
	/** 选项*/
	public String optionA = "";
	public String optionB = "";
	public String optionC = "";
	public String optionD = "";
	/** 答案选项,ABCD*/
	public String answerOption = "";
	/** 答案描述*/
	public String answerDesc = "";
	/** 图片地址*/
	public String picUrl = "";
	/** 做对次数*/
	public int duiCount;
	/** 做错次数*/
	public int cuoCount;
	/** 是否错题，0不是错题；1是错题*/
	public int isCuoti;
	/** 带图题目的图片*/
	public Bitmap bmp;

	@Override
	public String beanToString() {
		JSONObject json=new JSONObject();
		try {
			json.put("localId", localId);
			json.put("id", id);
			json.put("jibie", jibie);
			json.put("timuType", timuType);
			json.put("timu", timu);
			json.put("optionA", optionA);
			json.put("optionB", optionD);
			json.put("optionC", optionC);
			json.put("optionD", optionD);
			json.put("answerOption", answerOption);
			json.put("answerDesc", answerDesc);
			json.put("picUrl", picUrl);
			json.put("duiCount", duiCount);
			json.put("cuoCount", cuoCount);
			json.put("isCuoti", isCuoti);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return json.toString();
	}

	@Override
	public BaseBean stringToBean(String dataStringFromCacheDatabase) {
		try {
			JSONObject json=new JSONObject(dataStringFromCacheDatabase);
			localId = json.optInt("localId");
			id = json.optInt("id", id);
			jibie = json.optString("jibie", jibie);
			timuType = json.optString("timuType", timuType);
			timu = json.optString("timu", timu);
			optionA = json.optString("optionA", optionA);
			optionB = json.optString("optionB", optionD);
			optionC = json.optString("optionC", optionC);
			optionD = json.optString("optionD", optionD);
			answerOption = json.optString("answerOption", answerOption);
			answerDesc = json.optString("answerDesc", answerDesc);
			picUrl = json.optString("picUrl", picUrl);
			duiCount = json.optInt("duiCount", duiCount);
			cuoCount = json.optInt("cuoCount", cuoCount);
			isCuoti = json.optInt("isCuoti", isCuoti);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return this;
	}
	
	/** 释放图片*/
	public void recyleBmp() {
		if (this.bmp!=null&&!this.bmp.isRecycled()) {
			this.bmp.recycle();
			this.bmp = null;
		}
	}

}
